<?php
class info_rekap_keuangan_bulanan extends MY_Controller{
    var $data;
    function info_rekap_keuangan_bulanan(){
        parent::MY_Controller();
        $this->data['title'] = "Grafik Saldo Per Periode";
        $this->load->model("m_rekap_keuangan_bulanan");
        $this->load->plugin('jpgraph'); 
    }
    function index(){
        $this->get_rekap_keuangan_bulanan("all");
    }
    function search(){
        $jenis = $this->input->post("jenis");
        $url = $this->input->post("url");
        $Apply = $this->input->post("Apply");
        $bln1 = $this->input->post("bln1");
        $bln2 = $this->input->post("bln2");
        if($bln1 == '' && $bln2 == ''){
            $bln1 = 'Januari';
            $bln2 = 'Januari';
        }
        $thawal = $this->input->post("thawal");
        $thakhir = $this->input->post("thakhir");
        $params = "jenis_".$jenis."__bln1_".$bln1."__thawal_".$thawal."__bln2_".$bln2."__thakhir_".$thakhir."__Apply_".$Apply;
        
        redirect("$url/$params");
    }
    function get_rekap_keuangan_bulanan($params = "all"){
        $option = parsing_param2($params);
        $this->data['content'] = "rekap_keuangan_bulanan/info_rekap_keuangan_bulanan";
        $this->data['formTitle'] = "Parameter Pencarian";
        $this->data['searchLink'] = "info_rekap_keuangan_bulanan/get_rekap_keuangan_bulanan";
        if($option['Apply'] == TRUE){
        if($option['jenis'] == 'bulanan'){
            $this->data['listRekapKeuanganBulanan'] = $this->m_rekap_keuangan_bulanan->getListRekapKeuanganBulanan($option);
            foreach ($this->data['listRekapKeuanganBulanan']['master'] as $key => $row){
                $ydata[] = $row[0]['jumlah']/100000;
                $xdata[] = changePeriod($row[0]['id']);
            }
            $maxScale = ($this->data['listRekapKeuanganBulanan']['max']/100000);
            $graph = linechart($maxScale,$ydata,$xdata,'Grafik Rekap Keuangan Bulanan','Periode','Saldo Bulanan (x100.000 Rp.)');
            $graph_file_name = 'rekap_keuangan_bulanan.png';
        }else if($option['jenis'] == 'tahunan'){
            $this->data['listRekapKeuanganTahunan'] = $this->m_rekap_keuangan_bulanan->getListRekapKeuanganTahunan($option);
            foreach ($this->data['listRekapKeuanganTahunan']['master'] as $row){
                $ydata[] = $row['jumlah']/100000;
                $xdata[] = $row['tahun'];
            }
            $maxScale = ($this->data['listRekapKeuanganTahunan']['max']/100000);
            $graph = linechart($maxScale,$ydata,$xdata,'Grafik Rekap Keuangan Tahunan','Periode','Saldo Tahunan (x100.000 Rp.)');
            $graph_file_name = 'rekap_keuangan_tahunan.png';
        }
        $graph_temp_directory = 'temp';  
        $graph_file_location = $graph_temp_directory . '/' . $graph_file_name;
        if(file_exists($graph_file_location)){
            @unlink($graph_file_location);
        }
        $graph->Stroke('./'.$graph_file_location);
        $this->data['graph'] = $graph_file_location;
        }
        $this->render($this->data);
    }
}
?>
